package com.bjyhl.core.fragments.bottom;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.bjyhl.core.R;
import com.bjyhl.core.app.Latte;
import com.bjyhl.core.fragments.LatteFragment;

import me.yokeyword.fragmentation.ISupportFragment;
import me.yokeyword.fragmentation.SupportActivity;
import me.yokeyword.fragmentation.SupportFragment;
import me.yokeyword.fragmentation.SupportHelper;

/**
 * Created by Natalya on 2019/1/27 14:29
 * Note:
 */

public abstract class BottomItemFragment extends LatteFragment {

    // 再点一次退出程序时间设置
    private static final long WAIT_TIME = 2000L;
    private long TOUCH_TIME = 0;
    private static final String TAG = "BottomItemFragment";

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        BaseBottomFragment fragment = (BaseBottomFragment) getParentFragment();
//        fragment.setTitle("abc");
    }


    @Override
    public void onSupportVisible() {
        super.onSupportVisible();
        // 是否展示后退按钮
        if(getChildFragmentManager().getFragments().size() > 1) {
            ((BaseBottomFragment)getParentFragment()).showBackBtn(true);
        } else {
            ((BaseBottomFragment)getParentFragment()).showBackBtn(false);
        }
    }


    @Override
    public boolean onBackPressedSupport() {

        // 新返回处理
//        BaseBottomFragment fragment = (BaseBottomFragment) getParentFragment();
//        if (getChildFragmentManager().getFragments().size() <= 2) {
//            fragment.showBackBtn(false);
//        } else{
//            fragment.showBackBtn(true);
//        }
//
//        if (getChildFragmentManager().getFragments().size() > 1) {
//            getSupportDelegate().popChild();
//        }
        return true;

        // 原代码处理
//        if (System.currentTimeMillis() - TOUCH_TIME < WAIT_TIME) {
//            _mActivity.finish();
//        } else {
//            TOUCH_TIME = System.currentTimeMillis();
//            Toast.makeText(_mActivity, "双击退出" + Latte.getApplicationContext().getString(R.string.app_name), Toast.LENGTH_SHORT).show();
//        }
//        return true;
    }
}
